package com.live.stamp.web.message.controller;

import com.live.stamp.base.token.TokenAuth;
import com.live.stamp.base.validation.ParamHandlerManager;
import com.live.stamp.base.validation.ValidationEnum;
import com.live.stamp.global.commonenum.HandleTypeEnum;
import com.live.stamp.global.commonenum.ListTypeEnum;
import com.live.stamp.global.commonenum.SmsTemplateEnum;
import com.live.stamp.web.message.model.TMessage;
import com.live.stamp.web.message.service.MessageService;
import com.live.stamp.web.sms.service.model.SmsModel;
import com.live.stamp.web.user.service.UserService;
import com.live.stamp.web.user.vo.TUserVo;
import org.springframework.boot.container.core.common.BusinessException;
import org.springframework.boot.container.core.common.ServerResponse;
import org.springframework.boot.container.core.controller.BaseRestController;
import org.springframework.boot.container.core.log.ZKLogger;
import org.springframework.boot.container.core.log.ZKLoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 消息restController
 * @author cwd E-mail: wendong.cao@jsxfedu.com
 * @version 1
 * @date 2018/3/14 17:14
 */
@RestController
@RequestMapping("/message")
public class MessageRestController extends BaseRestController {
    private static final ZKLogger logger = ZKLoggerFactory.getLogger(MessageRestController.class);

    @Resource
    private MessageService messageService;

    /**
     * @api {post} /message/isHaveNewMessage 是否有新消息
     * @apiSampleRequest /message/isHaveNewMessage
     * @apiName isHaveNewMessage
     * @apiGroup message
     * @apiDescription 是否有新消息
     * @apiParam {token} token token
     * @apiParamExample {json} 参数示例:
     * {
     *
     * }
     * @apiSuccessExample {json} 返回示例:
     * HTTP/1.1 200 OK
        {
            "code": 200,
            "msg": null,
            "data": "1"             --1为有新消息， 0为没有新消息
        }
     */
    @RequestMapping(value = "/isHaveNewMessage", method = RequestMethod.POST)
    @TokenAuth
    public ServerResponse isHaveNewMessage(TUserVo tUserVo) {
        logger.info("enter isHaveNewMessage controller tUserVo:{}", tUserVo);

        ServerResponse serverResponse = new ServerResponse();

        try{
            serverResponse.setData(messageService.isHaveNewMessage());
            serverResponse.setCode(200);
        }catch (BusinessException e){
            serverResponse.setCode(ServerResponse.ERROR_BBUSINESS);
            serverResponse.setMsg(e.getMessage());
        }

        return serverResponse;
    }

    /**
     * @api {post} /message/homePageMessage 消息首页内容
     * @apiSampleRequest /message/homePageMessage
     * @apiName homePageMessage
     * @apiGroup message
     * @apiDescription 消息首页内容
     * @apiParam {token} token token
     * @apiParamExample {json} 参数示例:
     * {
     *
     * }
     * @apiSuccessExample {json} 返回示例:
     * HTTP/1.1 200 OK
        {
            "code": 200,
            "msg": "",
            "data": {
                "attenMessage": "0",            --新的关注：0无，1有
                "commonMessage": "0",           --新的评论：0无，1有
                "friendMessage": "0"            --好友申请：0无，1有
            }
        }
     */
    @RequestMapping(value = "/homePageMessage", method = RequestMethod.POST)
    @TokenAuth
    public ServerResponse homePageMessage(TUserVo tUserVo) {
        logger.info("enter homePageMessage controller tUserVo:{}", tUserVo);

        ServerResponse serverResponse = new ServerResponse();

        try{
            serverResponse.setData(messageService.homePageMessage());
            serverResponse.setCode(200);
        }catch (BusinessException e){
            serverResponse.setCode(ServerResponse.ERROR_BBUSINESS);
            serverResponse.setMsg(e.getMessage());
        }

        return serverResponse;
    }

    /**
     * @api {post} /message/commonMessageList 新的评论消息列表
     * @apiSampleRequest /message/commonMessageList
     * @apiName commonMessageList
     * @apiGroup message
     * @apiDescription 新的评论消息列表
     * @apiParam {token} token token
     * @apiParamExample {json} 参数示例:
     * {
     *
     * }
     * @apiSuccessExample {json} 返回示例:
     * HTTP/1.1 200 OK
    {
    "code": 200,
    "msg": "",
    "data": [
        {
            "id": "1f064085163682e27187DE506A5A8F38EC3B9040B521CD837F1",                --message id
            "toUserId": "5c73b876162f6b61a847DE506A5A8F38EC3B9040B521CD837F1",          --接收者
            "fromUserName": "馒头爸",                                                   --评论者姓名
            "fromUserPhoto": "http://inji.oss-cn-beijing.aliyuncs.com/C69427FF-1713-4D71-BF6D-50A1DB4ECC26",    --评论者头像
            "fromUserId": "4dde76b31631f6fec8795106ECE8932320DB52A8812F90BCE3B",        --评论者id
            "type": "COMM",
            "content": "lo\\Ud83d\\Ude0d\\Ud83d\\Ude0d",                                --评论内容
            "busiId": "65b99af81633307c60095106ECE8932320DB52A8812F90BCE3B",            --业务id，in迹id
            "createTime": "2018-05-16 17:00:45",                                        --小时时间
            "state": "1",                                                               --1未读，2已读
            "stampId": "",
            "stampUserId": "5c73b876162f6b61a847DE506A5A8F38EC3B9040B521CD837F1",       --in迹创建者id
            "stampUserName": "12333",                                                   --in迹创建者姓名
            "stampUserPhoto": "test",                                                   --in迹创建者头像
            "stampContent": "滨州的风情"                                                --in迹创内容
        }
    ]
    }
     */
    @RequestMapping(value = "/commonMessageList", method = RequestMethod.POST)
    @TokenAuth
    public ServerResponse commonMessageList(TMessage tMessage) {
        logger.info("enter commonMessageList controller tMessage:{}", tMessage);

        ServerResponse serverResponse = new ServerResponse();

        try{
            serverResponse.setData(messageService.getCommonMessageList(tMessage));
            serverResponse.setCode(200);
        }catch (BusinessException e){
            serverResponse.setCode(ServerResponse.ERROR_BBUSINESS);
            serverResponse.setMsg(e.getMessage());
        }

        return serverResponse;
    }

    /**
     * @api {post} /message/attenMessageList 新的关注
     * @apiSampleRequest /message/attenMessageList
     * @apiName attenMessageList
     * @apiGroup message
     * @apiDescription 新的关注
     * @apiParam {token} token token
     * @apiParamExample {json} 参数示例:
     * {
     *
     * }
     * @apiSuccessExample {json} 返回示例:
     * HTTP/1.1 200 OK
    {
    "code": 200,
    "msg": "",
    "data": [
        {
        "id": "6cbbc1fb163684225ee7DE506A5A8F38EC3B9040B521CD837F1",
        "toUserId": "5c73b876162f6b61a847DE506A5A8F38EC3B9040B521CD837F1",
        "fromUserName": "馒头爸",                                  --关注者用户名
        "fromUserPhoto": "http://inji.oss-cn-beijing.aliyuncs.com/C69427FF-1713-4D71-BF6D-50A1DB4ECC26",    --关注者头像地址
        "fromUserId": "4dde76b31631f6fec8795106ECE8932320DB52A8812F90BCE3B",    --关注者用户id
        "type": "ATTEN",
        "content": "好友关注",
        "busiId": "",
        "createTime": "2018-05-16 17:22:36",
        "state": "1"
        }
    ]
    }
     */
    @RequestMapping(value = "/attenMessageList", method = RequestMethod.POST)
    @TokenAuth
    public ServerResponse attenMessageList(TMessage tMessage) {
        logger.info("enter commonMessageList controller tMessage:{}", tMessage);

        ServerResponse serverResponse = new ServerResponse();

        try{
            serverResponse.setData(messageService.getAttenMessageList(tMessage));
            serverResponse.setCode(200);
        }catch (BusinessException e){
            serverResponse.setCode(ServerResponse.ERROR_BBUSINESS);
            serverResponse.setMsg(e.getMessage());
        }

        return serverResponse;
    }

    /**
     * @api {post} /message/getMessageInfo 查看一条消息内容
     * @apiSampleRequest /message/getMessageInfo
     * @apiName getMessageInfo
     * @apiGroup message
     * @apiDescription 查看一条消息内容
     * @apiParam {id} id messageId
     * @apiParam {token} token token
     * @apiParamExample {json} 参数示例:
     * {
     *
     * }
     * @apiSuccessExample {json} 返回示例:
     * HTTP/1.1 200 OK
    {
    "code": 200,
    "msg": "",
    "data": {
        "id": "1f064085163682e27187DE506A5A8F38EC3B9040B521CD837F1",
        "toUserId": "5c73b876162f6b61a847DE506A5A8F38EC3B9040B521CD837F1",
        "fromUserName": "馒头爸",
        "fromUserPhoto": "http://inji.oss-cn-beijing.aliyuncs.com/C69427FF-1713-4D71-BF6D-50A1DB4ECC26",
        "fromUserId": "4dde76b31631f6fec8795106ECE8932320DB52A8812F90BCE3B",
        "type": "COMM",
        "content": "lo\\Ud83d\\Ude0d\\Ud83d\\Ude0d",
        "busiId": "65b99af81633307c60095106ECE8932320DB52A8812F90BCE3B",
        "createTime": "2018-05-16 17:00:45",
        "state": "2"
    }
    }
     */
    @RequestMapping(value = "/getMessageInfo", method = RequestMethod.POST)
    @TokenAuth
    public ServerResponse getMessageInfo(TMessage tMessage) {
        logger.info("enter getMessageInfo controller tMessage:{}", tMessage);

        ServerResponse serverResponse = new ServerResponse();

        try{
            serverResponse.setData(messageService.getOneMessage(tMessage));
            serverResponse.setCode(200);
        }catch (BusinessException e){
            serverResponse.setCode(ServerResponse.ERROR_BBUSINESS);
            serverResponse.setMsg(e.getMessage());
        }

        return serverResponse;
    }


}
